package com.jia.interviewPro;

import java.util.LinkedList;

/**
 * 面试题 03.06. 动物收容所
 */
public class Pro0306 {
    LinkedList<int[]> list = new LinkedList<>();
    public Pro0306() {

    }

    public void enqueue(int[] animal) {
        list.addFirst(animal);
    }

    public int[] dequeueAny() {
        if(list.size() >0){
            return list.removeLast();
        }
        return new int[]{-1, -1};
    }

    public int[] dequeueDog() {
        if(list.size() > 0) {
            int index = list.size() - 1;
            while(index>=0) {
                if(list.get(index)[1] == 1) {
                    return list.remove(index);
                }
                --index;
            }
        }
        return new int[]{-1, -1};
    }

    public int[] dequeueCat() {
        if(list.size() > 0) {
            int index = list.size() - 1;
            while(index>=0) {
                if(list.get(index)[1] == 0) {
                    return list.remove(index);
                }
                --index;
            }
        }
        return new int[]{-1, -1};
    }
}
